package org.lex.keytool.ui.builder;

import java.util.HashMap;
import java.util.Map;

import org.lex.keytool.core.task.CreatePublicAndPrivateKeyTask;
import org.lex.keytool.core.task.ExportCertificateTask;
import org.lex.keytool.core.task.ImportCertificateTask;
import org.lex.keytool.core.task.Task;
import org.lex.keytool.ui.task.BaseTaskPane;
import org.lex.keytool.ui.task.CreatePublicAndPrivateKeyTaskPane;
import org.lex.keytool.ui.task.ExportCertificateTaskPane;
import org.lex.keytool.ui.task.ImportCertificateTaskPane;

public class TaskPaneBuilder {
	private static Map<Class<? extends Task>, Class<? extends BaseTaskPane>> taskPaneMap = new HashMap<Class<? extends Task>, Class<? extends BaseTaskPane>>();
	static {
		taskPaneMap.put(CreatePublicAndPrivateKeyTask.class, CreatePublicAndPrivateKeyTaskPane.class);
		taskPaneMap.put(ExportCertificateTask.class, ExportCertificateTaskPane.class);
		taskPaneMap.put(ImportCertificateTask.class, ImportCertificateTaskPane.class);
	}

	public BaseTaskPane createTaskPane(Class<? extends Task> taskClass) {
		Class<? extends BaseTaskPane> clz = taskPaneMap.get(taskClass);
		try {
			return clz.newInstance();
		} catch (InstantiationException e) {
			e.printStackTrace();
		} catch (IllegalAccessException e) {
			e.printStackTrace();
		}
		return null;
	}
}
